package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.TableColumn;
import com.egao.orderB.service.TableColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 * 表格显示列配置
 * @author : Doman
 * @date : 2021-09-01 15:19:33
 * @version ：1.0
 */

@Api(tags = "表格显示列配置")
@RestController
@RequestMapping("/api/orderB/tableColumn")
public class TableColumnController extends BaseController {

	@Autowired
	private TableColumnService tableColumnService;

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('orderB:tableColumn:list')")
    //@OperLog(value = "表格显示列配置", desc = "分页查询")
    @ApiOperation(value ="分页查询表格显示列配置",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "tableName:表名\n" +
        "orderNum:序号\n" +
        "title:列名\n" +
        "remark:备注\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, TableColumn tableColumn) throws Exception{
        return tableColumnService.list(page, tableColumn, getLoginUser());
    }

    /**
     * 查询全部表格显示列配置
     */
//    @PreAuthorize("hasAuthority('orderB:tableColumn:list')")
    //@OperLog(value = "表格显示列配置", desc = "查询全部")
    @ApiOperation("查询全部表格显示列配置")
    @PostMapping("/list")
    public JsonResult list(TableColumn tableColumn){
        return tableColumnService.list(tableColumn, getLoginUser());
    }

    /**
     * 根据id查询表格显示列配置
     */
//    @PreAuthorize("hasAuthority('orderB:tableColumn:list')")
    //@OperLog(value = "表格显示列配置", desc = "根据id查询")
    @ApiOperation("根据id查询表格显示列配置")
    @PostMapping("/get")
    public JsonResult get(TableColumn tableColumn) {
        return tableColumnService.getById(tableColumn);
		// 使用关联查询
        //PageParam<tableColumn> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<tableColumn> records = tableColumnService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加表格显示列配置
     */
//    @PreAuthorize("hasAuthority('orderB:tableColumn:save')")
    @OperLog(value = "表格显示列配置", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加表格显示列配置",notes = "" +
            "tableName:表名\n" +
            "值:bill 表示拖车列表\n" +
            "值:ocean 表示海运列表\n" +
            "值:applyC 表示报关列表\n" +
            "orderNum:序号\n" +
            "title:列名\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, TableColumn tableColumn) {
        return tableColumnService.save(tableColumn, getLoginUser());
    }

    /**
     * 修改表格显示列配置
     */
//    @PreAuthorize("hasAuthority('orderB:tableColumn:update')")
    @OperLog(value = "表格显示列配置", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改表格显示列配置",notes = "" +
            "id:id\n" +
            "tableName:表名\n" +
            "orderNum:序号\n" +
            "title:列名\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, TableColumn tableColumn) {
        return tableColumnService.update(tableColumn, getLoginUser());
    }

    /**
     * 删除表格显示列配置
     */
//    @PreAuthorize("hasAuthority('orderB:tableColumn:remove')")
    @OperLog(value = "表格显示列配置", desc = "删除", result = true)
    @ApiOperation("删除表格显示列配置")
    @PostMapping("/remove")
    public JsonResult remove(TableColumn tableColumn ) {
        return tableColumnService.remove(tableColumn, getLoginUser());
    }

    /**
     * 批量添加表格显示列配置
     */
    /**@RequiresPermissions("orderB:tableColumn:save")
    @OperLog(value = "表格显示列配置", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<TableColumn> list) {
        if (tableColumnService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改表格显示列配置
     */
    /**@RequiresPermissions("orderB:tableColumn:update")
    @OperLog(value = "表格显示列配置", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<TableColumn> batchParam) {
        if (batchParam.update(tableColumnService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除表格显示列配置
     */
    /**@RequiresPermissions("orderB:tableColumn:remove")
    @OperLog(value = "表格显示列配置", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (tableColumnService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
